package com.xupk.docking;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.unity3d.player.UnityPlayer;

public class U3DInterface {

	public static final String u3dObjName = "XUDockingCallback";
	public static final String callBackMethodName = "ReceiveMessage";

	public static void Call(String gameObjName, String methodName, String param) {
		Log.d("docking", "U3DInterface.Call: " + gameObjName + ", "
				+ methodName + ", " + param);
		UnityPlayer.UnitySendMessage(gameObjName, methodName, param);
	}

	public static void Call(String methodName, String param) {
		Log.d("docking", "U3DInterface.Call: " + methodName + ", " + param);
		UnityPlayer.UnitySendMessage(u3dObjName, methodName, param);
	}

	public static void SendMessage(U3DMessageType msgType, String json) {
		JSONObject jObject = null;
		try {
			jObject = new JSONObject();
			jObject.put("opt", msgType.ordinal());
			jObject.put("json", json);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		Log.d("docking",
				"U3DInterface.SendMessage jObject: " + jObject.toString());
		UnityPlayer.UnitySendMessage(u3dObjName, callBackMethodName,
				jObject.toString());
	}
}
